#include "Threads.h"

#define THREAD_STACK_SIZE	(512 * 1024)

Threads::Threads(void)
{
}

Threads::~Threads(void)
{
}

bool Threads::New(LPTHREAD_START_ROUTINE handler, LPVOID arg)
{
#ifdef WIN32
	DWORD dwThreadId;
	CreateThread(NULL, THREAD_STACK_SIZE, handler, arg, 0, &dwThreadId);
#else

	pthread_attr_t 	attr;
		
	int err = pthread_attr_init(&attr);
	if(err != 0)
	{
		return false;
	}

	size_t size = THREAD_STACK_SIZE;
	
	err = pthread_attr_setstacksize(&attr, size);
	
	if(err != 0)
	{
		return false;
	}

	err = pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
	if(err != 0)
	{
		return false;
	}

	pthread_t thread;
	err = pthread_create(&thread, &attr, handler, arg);
	if(err != 0)
	{
		return false;
	}

	pthread_attr_destroy (&attr);
#endif

	return true;
}